using System.Web.Mvc;
using Web.Components;
using System.Web.Helpers;
using System.Web.Routing;

namespace Web.BootstrapperTask
{
    public class RegisterDefaultRoute : IBootstrapperTask
    {
        private readonly RouteCollection routes;

        public RegisterDefaultRoute()
            : this(RouteTable.Routes)
        {
        }

        internal RegisterDefaultRoute(RouteCollection routes)
        {
            this.routes = routes;
        }

        public void Execute()
        {
            ModelBinders.Binders.Add(typeof(ShoppingCart), new ShoppingCartModelBinder());
            AreaRegistration.RegisterAllAreas();
            routes.IgnoreRoute("robots.txt");
            routes.IgnoreRoute("{file}.xml");
            routes.IgnoreRoute("{file}.htm");
            routes.IgnoreRoute("{file}.html");
            routes.IgnoreRoute("images/{*pathInfo}");
            routes.IgnoreRoute("javascripts/{*pathInfo}");
            routes.IgnoreRoute("stylesheets/{*pathInfo}");

            //routes.IgnoreRoute("{images}/{*pathInfo}", new { folder = "images" });

            routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
            routes.IgnoreRoute("{*favicon}", new { favicon = @"(.*/)?favicon.ico(/.*)?" });
            routes.IgnoreRoute("{*staticfile}", new { staticfile = @".*\.(jpg|gif|jpeg|png|js|css|htm|html|htc)$" });

            routes.MapRoute("Default", "{controller}/{action}/{param}", new { controller = "Home", action = "Index", param = UrlParameter.Optional } ,new[] { "Web.Controllers" });
            AntiForgeryConfig.CookieName = "RequestVerificationToken";
        }
    }
}